/*
 * @(#)AtnaMessageProcessor.java
 * Date 2013-11-05
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.atna.client;

import com.nesscomputing.syslog4j.SyslogFacility;
import com.nesscomputing.syslog4j.SyslogLevel;

import com.nesscomputing.syslog4j.impl.message.processor.SyslogMessageProcessor;

import org.apache.commons.lang3.ClassUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import us.hornerscorners.lamppost.utils.UTCDateUtils;


/**
 * Class description
 *
 *
 * @version        v1.0, 2013-11-05
 * @author         Jim Horner
 */
public class AtnaMessageProcessor extends SyslogMessageProcessor {

    /** Field description */
    private final AtnaContext atnaContext;

    /** Field description */
    private final Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * Constructs ...
     *
     * @param atnaContext
     */
    public AtnaMessageProcessor(AtnaContext atnaContext) {

        super();
        this.atnaContext = atnaContext;
    }

    /**
     * Method description
     *
     *
     * @param facility
     * @param level
     * @param localName
     * @param localProcessId
     * @param sendLocalTimestamp
     * @param sendLocalName
     *
     * @return
     */
    @Override
    public String createSyslogHeader(SyslogFacility facility, SyslogLevel level,
                                     String localName, String localProcessId,
                                     boolean sendLocalTimestamp, boolean sendLocalName) {

        int pri = facility.getValue() + level.getValue();
        String now = UTCDateUtils.formatDate(UTCDateUtils.now(),
                         UTCDateUtils.ISO_DATE_TIME_FORMAT);

        return String.format("<%d>1 %s %s %s %s IHE+RFC-3881 - ", pri, now,
                             this.atnaContext.getHostName(),
                             ClassUtils.getShortCanonicalName(getClass()),
                             this.atnaContext.getProcessId());
    }
}
